package calculators;

import algorithm.AlgorithmParameters;
import herd.Food;
import herd.Krill;
import utils.Position;
import utils.PositionMath;

import java.util.List;

public class ForagingCalculator {
    private final PositionMath positionMath = new PositionMath();
    private final BetaCalculator betaCalculator = new BetaCalculator();
    public void calculateForagingMotion(List<Krill> herd, AlgorithmParameters parameters, Food food){
         for(Krill krill: herd){
             Position oldForaging = positionMath.multiplyPositionByScalar(krill.getForagingMotion(),parameters.inertiaForagingWeight);
             Position betaPosition = betaCalculator.calculateBeta(krill,food,parameters);
             positionMath.multiplyPositionImplicitly(betaPosition,parameters.Vf);

             calculateNewForaging(krill, oldForaging, betaPosition);
         }
    }

    private void calculateNewForaging(Krill krill, Position oldForaging, Position betaPosition) {
        Position newPosition = positionMath.addPositions(betaPosition,oldForaging);
        krill.setForagingMotion(newPosition);
    }
}
